import moment from 'moment'
import dt from '@dt/dt'
import table from '@/components/dt/table/render.js'

function options(name) {
  return [
    {
      type: 'index',
      title: '序号',
      width: 70
    },
    {
      field: 'postName',
      title: '岗位',
      width: 150
    },
    {
      field: 'rankName',
      title: '职级'
    },
    {
      title: '奖金比例(万分之)',
      width: 160,
      cell: {
        edit: {
          key: 'bonusRatio',
          disabled: name !== 'levelPointsEdit' ? true : false,
          input: {
            type: 'number'
          }
        }
      }
    }
  ]
}

function jumpOptions(name) {
  return [
    {
      type: 'index',
      title: '序号',
      width: 70
    },
    {
      field: 'jumpName',
      title: '跳点方案名称',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.jumpName
          })
        }
      }
    },
    {
      field: 'jumpType',
      title: '跳点取值',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.dictInfo().__value('JumpPointType', params.row.jumpType)
          })
        }
      }
    },
    {
      field: 'target',
      title: '跳点指标',
      minWidth: 220,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: `${dt.dictInfo().__value('JumpTarget', params.row.targetType)}-${dt
              .dictInfo()
              .__value('TargetValue', params.row.targetValue)}`
          })
        }
      }
    },
    {
      field: 'postNames',
      title: '涉及岗位',
      minWidth: 200,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.postNames
          })
        }
      }
    },
    {
      field: 'effectiveDate',
      title: '生效日期',
      minWidth: 210,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: `${moment(params.row.effectiveStartDate).format('YYYY-MM-DD')} ~ ${moment(
              params.row.effectiveEndDate
            ).format('YYYY-MM-DD')}`
          })
        }
      }
    },
    {
      field: 'handles',
      title: '操作',
      fixed: 'right',
      width: 100,
      cell: (row) => {
        return {
          btn: [
            {
              title: name !== 'levelPointsEdit' ? '查看' : '',
              event: 'onDetail'
            },
            {
              title: name == 'levelPointsEdit' ? '编辑' : '',
              event: 'onUpdate'
            },
            {
              title: name == 'levelPointsEdit' ? '删除' : '',
              event: 'onDelete'
            }
          ]
        }
      }
    }
  ]
}

export default {
  options,
  jumpOptions
}
